<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="店名" prop="shopName">
        <el-input v-model="queryParams.shopName" placeholder="请输入店名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="店主" prop="shopOwner">
        <el-input v-model="queryParams.shopOwner" placeholder="请输入店主" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="详细地址" prop="shopAddress">
        <el-input v-model="queryParams.shopAddress" placeholder="请输入店家详细地址" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系电话" prop="shopPhone">
        <el-input v-model="queryParams.shopPhone" placeholder="请输入联系电话" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
     <!-- <el-form-item label="身份证号码" prop="identityCard">
        <el-input v-model="queryParams.identityCard" placeholder="请输入身份证号码" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="身份证正面" prop="identityCardFront">
        <el-input v-model="queryParams.identityCardFront" placeholder="请输入身份证正面" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="身份证反面" prop="identityCardReverse">
        <el-input v-model="queryParams.identityCardReverse" placeholder="请输入身份证反面" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="营业执照链接" prop="businessLicense">
        <el-input v-model="queryParams.businessLicense" placeholder="请输入营业执照链接" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="店面logo" prop="shopUrl">
        <el-input v-model="queryParams.shopUrl" placeholder="请输入店面logo" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="商户号" prop="mchNo">
        <el-input v-model="queryParams.mchNo" placeholder="请输入商户号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="应用ID" prop="appId">
        <el-input v-model="queryParams.appId" placeholder="请输入应用ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['shop:shop:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['shop:shop:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['shop:shop:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['shop:shop:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="shopList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="店家ID" width="180" align="center" prop="shopId" />
      <el-table-column label="店名" align="center" prop="shopName" />
      <el-table-column label="店面logo" align="center" prop="shopUrl">
        <template slot-scope="scope">
          <img width="100" height="100" :src="baseUrl+scope.row.shopUrl" />
        </template>
      </el-table-column>
      <el-table-column label="店主" align="center" prop="shopOwner" />
      <el-table-column label="店家详细地址" align="center" prop="shopAddress" />
      <el-table-column label="联系电话" align="center" prop="shopPhone" />
      <el-table-column label="身份证号码" align="center" prop="identityCard" />
    <!--  <el-table-column label="身份证正面" align="center" prop="identityCardFront" />
      <el-table-column label="身份证反面" align="center" prop="identityCardReverse" /> -->
   <!--   <el-table-column label="营业执照链接" align="center" prop="businessLicense">
        <template slot-scope="scope">
          <img width="100" height="100" :src="baseUrl+scope.row.businessLicense" />
        </template>
      </el-table-column> -->


<!--      <el-table-column label="商户号" align="center" prop="mchNo" />
      <el-table-column label="应用ID" align="center" prop="appId" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['shop:shop:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['shop:shop:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改店家信息对话框 -->
    <el-dialog :title="title" :visible.sync="open"  append-to-body center>
      <el-form  style="width:80%; margin-left:10%;" label-position="top" class="demo" ref="form" :model="form" :rules="rules" >
        <el-form-item label="店名" prop="shopName">
          <el-input v-model="form.shopName" placeholder="请输入店名" />
        </el-form-item>
        <el-form-item label="店主" prop="shopOwner">
          <el-input v-model="form.shopOwner" placeholder="请输入店主" />
        </el-form-item>
        <el-form-item label="店家详细地址" prop="shopAddress">
          <el-input v-model="form.shopAddress" placeholder="请输入店家详细地址" />
        </el-form-item>
        <el-form-item label="联系电话" prop="shopPhone">
          <el-input v-model="form.shopPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="identityCard">
          <el-input v-model="form.identityCard" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="身份证正面" prop="identityCardFront">
          <el-input v-model="form.identityCardFront" placeholder="请输入身份证正面" />
        </el-form-item>
        <el-form-item label="身份证反面" prop="identityCardReverse">
          <el-input v-model="form.identityCardReverse" placeholder="请输入身份证反面" />
        </el-form-item>
        <el-form-item label="营业执照链接" prop="businessLicense">
          <image-upload v-model="form.businessLicense" :limit="1" />
        </el-form-item>

        <el-form-item label="店面logo图片" prop="shopUrl">
          <image-upload v-model="form.shopUrl" :limit="1" />
        </el-form-item>

        <el-form-item label="商户号" prop="mchNo">
          <el-input v-model="form.mchNo" placeholder="请输入商户号" />
        </el-form-item>
        <el-form-item label="应用ID" prop="appId">
          <el-input v-model="form.appId" placeholder="请输入应用ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listShop,
    getShop,
    delShop,
    addShop,
    updateShop
  } from "@/api/shop/shop";
  import store from '@/store';
  export default {
    name: "Shop",
    data() {
      return {
        baseUrl: process.env.VUE_APP_BASE_IMAGE_URL,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 店家信息表格数据
        shopList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          sysUserid:store.getters.userId,
          shopName: null,
          shopOwner: null,
          shopAddress: null,
          shopPhone: null,
          identityCard: null,
          identityCardFront: null,
          identityCardReverse: null,
          businessLicense: null,
          shopUrl: null,
          mchNo: null,
          appId: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询店家信息列表 */
      getList() {
        this.loading = true;
        listShop(this.queryParams).then(response => {
          this.shopList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          shopId: null,
          shopName: null,
          shopOwner: null,
          shopAddress: null,
          shopPhone: null,
          identityCard: null,
          identityCardFront: null,
          identityCardReverse: null,
          businessLicense: null,
          shopUrl: null,
          mchNo: null,
          appId: null,
          createTime: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.shopId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加店家信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const shopId = row.shopId || this.ids
        getShop(shopId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改店家信息";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.shopId != null) {
              updateShop(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addShop(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const shopIds = row.shopId || this.ids;
        this.$modal.confirm('是否确认删除店家信息编号为"' + shopIds + '"的数据项？').then(function() {
          return delShop(shopIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('shop/shop/export', {
          ...this.queryParams
        }, `shop_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>


<style>
  .demo::-webkit-scrollbar {

    display: none;
    /* Chrome Safari */

  }



  .demo {

    scrollbar-width: none;
    /* firefox */

    -ms-overflow-style: none;
    /* IE 10+ */

    overflow-x: hidden;

    overflow-y: auto;
    height: 400px;
  }
</style>
